****************************************************************************************************
****************************************************************************************************
*THIS DO-FILE RUNS THE SYNTHETIC CONTROL ANALYSIS AND CREATES THE OUTPUT DATA ANALYSED IN THE PAPER. 
*RUNNING THIS DO-FILE WILL TAKE SEVERAL WEEKS TO COMPLETE ON A STANDARD PC!*************************
*THE OUTPUT FILES NECESSARY TO REPLICATE THE RESULTS ARE INCLUDED IN THE REPLICATION FILES**********
****************************************************************************************************
****************************************************************************************************

*You need the Synth package to run the estimations. To install Synth for Stata type: ssc install synth, replace all

*Childcare: Model 1
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare lnpop elderly children young Share_childcare(1994) Share_childcare(1992) Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980) Share_childcare(1995) Share_childcare(1993) Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth1_`i'.dta, replace)
}


*Childcare: Model 2
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare Share_childcare(1994) Share_childcare(1992) Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980) Share_childcare(1995) Share_childcare(1993) Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth2_`i'.dta, replace)
}


*Childcare: Model 3
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare lnpop elderly children young Share_childcare(1994) Share_childcare(1992) Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980), nested trunit(`i') trperiod(1996)  keep(synth3_`i'.dta, replace)
}

*Childcare: Model 4
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare  Share_childcare(1994) Share_childcare(1992) Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980), nested trunit(`i') trperiod(1996)  keep(synth4_`i'.dta, replace)
}


*Childcare: Model 5
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare  lnpop elderly children young Share_childcare(1995) Share_childcare(1993) Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth5_`i'.dta, replace)
}

*Childcare: Model 6
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare Share_childcare(1995) Share_childcare(1993) Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth6_`i'.dta, replace)
}

*Childcare: Model 7
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare lnpop elderly children young  Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980)  Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth7_`i'.dta, replace)
}

*Childcare: Model 8
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980)  Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981), nested trunit(`i') trperiod(1996)  keep(synth8_`i'.dta, replace)
}

*Childcare: Model 9
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare lnpop elderly children young   Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980)   Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981) , nested trunit(`i') trperiod(1996)  keep(synth9_`i'.dta, replace)
}


*Childcare: Model 10
clear
use "childinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "childinput.dta"
set matsize 800
tsset komnr year
Synth Share_childcare Share_childcare(1990) Share_childcare(1988) Share_childcare(1986) Share_childcare(1984) Share_childcare(1982) Share_childcare(1980)   Share_childcare(1991) Share_childcare(1989) Share_childcare(1987) Share_childcare(1985) Share_childcare(1983) Share_childcare(1981) , nested trunit(`i') trperiod(1996)  keep(synth10_`i'.dta, replace)
}

*Education: Model 1
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education lnpop elderly children young Share_education(1994) Share_education(1992) Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980) Share_education(1995) Share_education(1993) Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed1_`i'.dta, replace)
}


*Education: Model 2
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education Share_education(1994) Share_education(1992) Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980) Share_education(1995) Share_education(1993) Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed2_`i'.dta, replace)
}


*Education: Model 3
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education lnpop elderly children young Share_education(1994) Share_education(1992) Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980), nested trunit(`i') trperiod(1996)  keep(synthed3_`i'.dta, replace)
}

*Education: Model 4
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education  Share_education(1994) Share_education(1992) Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980), nested trunit(`i') trperiod(1996)  keep(synthed4_`i'.dta, replace)
}

*Education: Model 5
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education  lnpop elderly children young Share_education(1995) Share_education(1993) Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed5_`i'.dta, replace)
}


*Education: Model 6
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education Share_education(1995) Share_education(1993) Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed6_`i'.dta, replace)
}


*Education: Model 7
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education lnpop elderly children young  Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980)  Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed7_`i'.dta, replace)
}

*Education: Model 8
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980)  Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981), nested trunit(`i') trperiod(1996)  keep(synthed8_`i'.dta, replace)
}

*Education: Model 9
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education lnpop elderly children young   Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980)   Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981) , nested trunit(`i') trperiod(1996)  keep(synthed9_`i'.dta, replace)
}

*Education: Model 10
clear
use "eduinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "eduinput.dta"
set matsize 800
tsset komnr year
Synth Share_education Share_education(1990) Share_education(1988) Share_education(1986) Share_education(1984) Share_education(1982) Share_education(1980)   Share_education(1991) Share_education(1989) Share_education(1987) Share_education(1985) Share_education(1983) Share_education(1981) , nested trunit(`i') trperiod(1996)  keep(synthed10_`i'.dta, replace)
}

*Elderlycare: Model 1
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare lnpop elderly children young Share_elderlycare(1994) Share_elderlycare(1992) Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980) Share_elderlycare(1995) Share_elderlycare(1993) Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel1_`i'.dta, replace)
}

*Elderlycare: Model 2
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare Share_elderlycare(1994) Share_elderlycare(1992) Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980) Share_elderlycare(1995) Share_elderlycare(1993) Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel2_`i'.dta, replace)
}


*Elderlycare: Model 3
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare lnpop elderly children young Share_elderlycare(1994) Share_elderlycare(1992) Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980), nested trunit(`i') trperiod(1996)  keep(synthel3_`i'.dta, replace)
}


*Elderlycare: Model 4
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare  Share_elderlycare(1994) Share_elderlycare(1992) Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980), nested trunit(`i') trperiod(1996)  keep(synthel4_`i'.dta, replace)
}

*Elderlycare: Model 5
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare  lnpop elderly children young Share_elderlycare(1995) Share_elderlycare(1993) Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel5_`i'.dta, replace)
}

*Elderlycare: Model 6
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare Share_elderlycare(1995) Share_elderlycare(1993) Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel6_`i'.dta, replace)
}

*Elderlycare: Model 7
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare lnpop elderly children young  Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980)  Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel7_`i'.dta, replace)
}


*Elderlycare: Model 8
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980)  Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981), nested trunit(`i') trperiod(1996)  keep(synthel8_`i'.dta, replace)
}

*Elderlycare: Model 9
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare lnpop elderly children young   Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980)   Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981) , nested trunit(`i') trperiod(1996)  keep(synthel9_`i'.dta, replace)
}

*Elderlycare: Model 10
clear
use "elcinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "elcinput.dta"
set matsize 800
tsset komnr year
Synth Share_elderlycare Share_elderlycare(1990) Share_elderlycare(1988) Share_elderlycare(1986) Share_elderlycare(1984) Share_elderlycare(1982) Share_elderlycare(1980)   Share_elderlycare(1991) Share_elderlycare(1989) Share_elderlycare(1987) Share_elderlycare(1985) Share_elderlycare(1983) Share_elderlycare(1981) , nested trunit(`i') trperiod(1996)  keep(synthel10_`i'.dta, replace)
}

*Health care: Model 1
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial lnpop elderly children young Share_healthsocial(1994) Share_healthsocial(1992) Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980) Share_healthsocial(1995) Share_healthsocial(1993) Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe1_`i'.dta, replace)
}

*Health care: Model 2
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial Share_healthsocial(1994) Share_healthsocial(1992) Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980) Share_healthsocial(1995) Share_healthsocial(1993) Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe2_`i'.dta, replace)
}

*Health care: Model 3
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial lnpop elderly children young Share_healthsocial(1994) Share_healthsocial(1992) Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980), nested trunit(`i') trperiod(1996)  keep(synthhe3_`i'.dta, replace)
}

*Health care: Model 4
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial  Share_healthsocial(1994) Share_healthsocial(1992) Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980), nested trunit(`i') trperiod(1996)  keep(synthhe4_`i'.dta, replace)
}

*Health care: Model 5
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial  lnpop elderly children young Share_healthsocial(1995) Share_healthsocial(1993) Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe5_`i'.dta, replace)
}

*Health care: Model 6
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial Share_healthsocial(1995) Share_healthsocial(1993) Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe6_`i'.dta, replace)
}

*Health care: Model 7
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial lnpop elderly children young  Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980)  Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe7_`i'.dta, replace)
}

*Health care: Model 8
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980)  Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981), nested trunit(`i') trperiod(1996)  keep(synthhe8_`i'.dta, replace)
}

*Health care: Model 9
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial lnpop elderly children young   Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980)   Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981) , nested trunit(`i') trperiod(1996)  keep(synthhe9_`i'.dta, replace)
}

*Health care: Model 10
clear
use "healthinput.dta"
levelsof komnr, local(levels)
foreach i of local levels {
clear all
use "healthinput.dta"
set matsize 800
tsset komnr year
Synth Share_healthsocial Share_healthsocial(1990) Share_healthsocial(1988) Share_healthsocial(1986) Share_healthsocial(1984) Share_healthsocial(1982) Share_healthsocial(1980)   Share_healthsocial(1991) Share_healthsocial(1989) Share_healthsocial(1987) Share_healthsocial(1985) Share_healthsocial(1983) Share_healthsocial(1981) , nested trunit(`i') trperiod(1996)  keep(synthhe10_`i'.dta, replace)
}


*CREATING HELP FILES AND ANALYSES FILES
*CHILDCARE
*Estimates
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synth`t'_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
drop if _time>2000
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
gen model = `t'
save synth_out`t'_`i'.dta, replace
}
}

*p-values, rmspe og post-mspe
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synth_out`t'_`i'.dta, clear
keep if _time==2000
keep premspe postmspe RMSPE   komnr model
save synthmspe`t'_`i'.dta, replace
}
}

clear
use synthmspe1_615.dta
foreach t of numlist 2 3 4 5 6 7 8 9 10{
append using synthmspe`t'_615.dta
}
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthmspe`t'_`i'.dta
}
}

 save "childcareoutput.dta", replace
 
 
*CREATING HELP FILES AND ANALYSES FILES
*EDUCATION
*Estimates
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10 {
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthed`t'_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
drop if _time>2000
gen pre = 1 if _time<1996
gen post = 1 if _time>1995 
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
gen model = `t'
save synthed_out`t'_`i'.dta, replace
}
}

*p-values, rmspe og post-mspe
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthed_out`t'_`i'.dta, clear
keep if _time==2000
keep premspe postmspe RMSPE   komnr model
save synthedmspe`t'_`i'.dta, replace
}
}

clear
use synthedmspe1_615.dta
foreach t of numlist 2 3 4 5 6 7 8 9 10 {
append using synthedmspe`t'_615.dta
}
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthedmspe`t'_`i'.dta
}
}

 save "educationoutput.dta", replace
 
 
*CREATING HELP FILES AND ANALYSES FILES
*ELDERLYCARE
*Estimates
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthel`t'_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
drop if _time>2000
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
gen model = `t'
save synthel_out`t'_`i'.dta, replace
}
}

*p-values, rmspe og post-mspe
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthel_out`t'_`i'.dta, clear
keep if _time==2000
keep premspe postmspe RMSPE   komnr model
save synthelmspe`t'_`i'.dta, replace
}
}

clear
use synthelmspe1_615.dta
foreach t of numlist 2 3 4 5 6 7 8 9 10{
append using synthelmspe`t'_615.dta
}
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthelmspe`t'_`i'.dta
}
} 

save "elderlyoutput.dta", replace
 
 
   
*CREATING HELP FILES AND ANALYSES FILES
*HEALTHCARE
*Estimates
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthhe`t'_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
drop if _time>2000
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
gen model = `t'
save synthhe_out`t'_`i'.dta, replace
}
}

*p-values, rmspe og post-mspe
clear
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthhe_out`t'_`i'.dta, clear
keep if _time==2000
keep premspe postmspe RMSPE   komnr model
save synthhemspe`t'_`i'.dta, replace
}
}

clear
use synthhemspe1_615.dta
foreach t of numlist 2 3 4 5 6 7 8 9 10{
append using synthhemspe`t'_615.dta
}
foreach t of numlist 1 2 3 4 5 6 7 8 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthhemspe`t'_`i'.dta
}
}

save "healthoutput.dta", replace


*CREATING FILES TO GRAPH PLACEBO ESTIMATES
*childcare
clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synth3_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
save synth_out3_`i'.dta, replace
}

use synth_out3_615.dta, clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030 1635 {
append using synth_out3_`i'.dta
}
save "childcare_model3.dta", replace


*education
clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthed9_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
gen pre = 1 if _time<1996
gen post = 1 if _time>1995 
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
save synthed_out9_`i'.dta, replace
}

use synthed_out9_615.dta, clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030 1635 {
append using synthed_out9_`i'.dta
}
save "education_model9.dta", replace

*elderly
clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthel9_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
save synthel_out9_`i'.dta, replace
}

use synthel_out9_615.dta, clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030 1635 {
append using synthel_out9_`i'.dta
}
save "elderly_model9.dta", replace

*health
clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 615 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
use synthhe3_`i'.dta, clear
drop _Co_Number _W_Weight
drop if _time==.
gen pre = 1 if _time<1996
gen post = 1 if _time>1995
bys pre: gen nr = _n
by pre, sort: egen max = max(nr)
gen spe  = (_Y_treated - _Y_synthetic)^2
bys pre: egen sum_spe = sum(spe)
gen sum_spe_post = sum_spe/max
su sum_spe_post if pre == 1
gen premspe = r(mean)
su sum_spe_post if post == 1
gen postmspe = r(mean)
gen RMSPE = postmspe/premspe
gen komnr = `i'
save synthhe_out3_`i'.dta, replace
}

use synthhe_out3_615.dta, clear
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030 1635 {
append using synthhe_out3_`i'.dta
}
save "health_model3.dta", replace



*MODEL AVERAGE INFERENCE P-VALUES
*childcare
clear
use synthmspe1_615.dta
foreach t of numlist   2 3 4 9 10{
append using synthmspe`t'_615.dta
}
foreach t of numlist   2 3 4 5 6{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthmspe`t'_`i'.dta
}
}

save "childcare_avg_p.dta", replace


*education
clear
use synthedmspe1_615.dta, clear
foreach t of numlist 2 3 4 9 10{
append using synthedmspe`t'_615.dta
}
foreach t of numlist 2 3 4 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthedmspe`t'_`i'.dta
}
}

save "education_avg_p.dta", replace

*elderlycare
*p-value
clear
use synthelmspe1_615.dta, clear
foreach t of numlist 2 7 8  9 10{
append using synthelmspe`t'_615.dta
}
foreach t of numlist 2 3 4 9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthelmspe`t'_`i'.dta
}
}

save "elderly_avg_p.dta", replace


*health care
*p-value
clear
use synthhemspe1_615.dta
foreach t of numlist 2 3  5 6 7 8  9 10{
append using synthhemspe`t'_615.dta
}
foreach t of numlist 2 3  5 6 7 8  9 10{
foreach i of numlist 121 428 430 432 434 437 438 439 511 512 513 514 515 517 540 541 542 543 544 545 616 617 618 619 620 621 633 821 826 828 829 830 831 833 834 929 938 940 941 1003 1026 1034 1046 1133 1134 1135 1144 1151 1211 1223 1224 1227 1233 1234 1238 1244 1252 1264 1265 1266 1411 1412 1413 1416 1418 1420 1421 1424 1426 1438 1439 1441 1515 1524 1525 1539 1545 1546 1560 1563 1566 1567 1573 1612 1617 1620 1621 1627 1630 1632 1633 1634 1635 1640 1644 1665 1711 1717 1718 1736 1738 1739 1740 1742 1743 1748 1749 1750 1751 1755 1811 1815 1816 1818 1825 1826 1827 1828 1834  1835 1836 1837 1838 1839 1848 1849 1850 1851 1853 1854 1856 1857 1860 1866 1867 1868 1870 1871 1917 1919 1922 1924 1925 1926 1927 1929 1931 1933 1939 1943 2002 2011 2015 2017 2020 2021 2022 2023 2024 2025 2027 2028 2030   {
append using synthhemspe`t'_`i'.dta
}
}

save "health_avg_p.dta", replace
